package stringdemo;

import java.util.Scanner;
import java.util.stream.Stream;

public class StringDemo7 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int money;
        while(true){
            System.out.println("请输入一个金额");
            money = sc.nextInt();
            if(money >=0 && money <= 9999999){
                break;
            }else{
                System.out.println("金额无效");
            }
        }

        //得到money里面的每一个数,再转为中文
        String numberStr = "";
        while(true){
            int ge = money % 10;
            String number = getNumber(ge);
            numberStr = number + numberStr;
            money = money / 10;

            if(money == 0){
                break;
            }
        }
        System.out.println(numberStr);

        //3.在前面补零
        int count = 7 - numberStr.length();
        for (int i = 0; i < count; i++) {
            numberStr = "零" + numberStr;
        }
        System.out.println(numberStr);

        String result = "";
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < numberStr.length(); i++) {
            char c = numberStr.charAt(i);
            result =result + c + arr[i];

        }
        System.out.print(result);
    }

    public static String getNumber(int number){
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        String mony = arr[number];
        return mony;
    }
}
